<template>
  <div>
    <el-form :inline="true" label-width="120px">
      <el-row type="flex" justify="start">
        <el-col :span="8">
          <el-form-item label="快递员账号：">
            <el-input
              v-model.trim="data.account"
              placeholder="请输入快递员账号"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="快递员姓名：">
            <el-input
              v-model.trim="data.name"
              placeholder="请输入快递员姓名"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="快递员手机号：">
            <el-input
              v-model.trim="data.phone"
              placeholder="请输入快递员手机"
            />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="所属机构：">
            <el-select v-model="value" placeholder="请选择所属机构">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="margin-left:18px">
          <el-form-item>
            <el-button type="primary" @click="getData">提交</el-button>
            <el-button @click="reSet">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple-dark context">
            <el-table :data="tableData" stripe style="width: 100%;border: 1px solid #ebeef5" :row-class-name="tableRowClassName">
              <el-table-column height="20px" align="center" type="index" label="序号" width="100" />
              <el-table-column prop="account" label="快递员账号" />
              <el-table-column prop="name" label="快递员姓名" />
              <el-table-column prop="mobile" label="快递员手机号" />
              <el-table-column prop="agency.name" label="所属机构" />
              <el-table-column prop="status" label="工作状态" align="center">
                <template v-slot="{row}">
                  <div v-if="row.status === 1" class="center">
                    <div class="green" /> <span> 上班</span>
                  </div>
                  <div v-else>
                    <div class="red" /> <span> 休息</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column fixed="right" align="center" label="操作" width="200">
                <template>
                  <el-button type="text" size="small" @click="$router.push('/branches/operational-range/jobArea')">作业范围分配</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="block">
              <el-pagination
                :current-page="data.page"
                :page-size="data.pageSize"
                :page-sizes="[10,20,30,40]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getCourierList } from '@/api/operationalRange'
export default {
  data() {
    return {
      data: {
        account: '',
        agentId: '',
        name: '',
        phone: '',
        page: 1,
        pageSize: 10
      },
      options: [],
      value: '',
      tableData: [],
      total: 0

    }
  },
  created() {
    this.getData()
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },

    // 获取快递员信息列表
    async getData() {
      const res = await getCourierList(this.data)
      console.log(res)
      this.tableData = res.items
      this.data.page = res.page
      this.data.pageSize = res.pageSize
      this.total = +res.counts
    },
    handleSizeChange(val) {
      this.data.pageSize = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.data.page = val
      this.getData()
    },
    // 重置表单
    reSet() {
      this.data.account = ''
      this.data.agentId = ''
      this.data.name = ''
      this.data.phone = ''
      this.getData()
    }
  }
}
</script>

<style lang="scss" scoped>
*{
  box-sizing: border-box;
}
  .el-row {
    padding: 20px 20px 0;
    margin-bottom: 20px;
    flex-wrap: wrap;
    background: #ffffff;
    border-radius: 4px;

  }
  .el-col {
    .context{
    padding: 20px 20px 20px 20px;
    height: 100%;
    }
  }

  .el-form-item {
    .el-input{
      width:380px ;
    }
    .el-select{
      width: 380px;
    }
    .el-button{
      height: 40px;
      width: 100px;
    }
  }

  .block{
    display: flex;
    margin-top: 30px;
    justify-content: center;
  }
   .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  .green{
    display: inline-block;
    background: #1dc779;
    width: 7px;
    margin-right: 5px;
    height: 7px;
    border-radius: 50%;
  }
  .center{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .red{
    display: inline-block;
    background: red;
    width: 7px;
    height: 7px;
    margin-right: 5px;
    border-radius: 50%;
  }

</style>
